﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace Himp.Setl
{
    /// <summary>
    /// 结算类别服务
    /// </summary>
    public class SetlTypeService : CrudAppService<SetlType, SetlTypeDto, Guid, SetlTypeInput, SetlTypeCreateDto, SetlTypeCreateOrUpdateBaseDto>, ISetlTypeService
    {
        private IRepository<SetlType, Guid> _SetlTypeRepository;

        public SetlTypeService(IRepository<SetlType, Guid> SetlTypeRepository) : base(SetlTypeRepository)
        {
            _SetlTypeRepository = SetlTypeRepository;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public override async Task<PagedResultDto<SetlTypeDto>> GetListAsync(SetlTypeInput input)
        {
            var iQuery = await _SetlTypeRepository.WithDetailsAsync();

            if (input.Pi == 0)
            {
                var itemsDto = ObjectMapper.Map<List<SetlType>, List<SetlTypeDto>>(iQuery.ToList());

                return new PagedResultDto<SetlTypeDto>(itemsDto.Count, itemsDto);
            }
            else
            {
                var totalCount = iQuery.Count();
                var items = iQuery.Page(input.Pi, input.Ps);
                var itemsDto = ObjectMapper.Map<List<SetlType>, List<SetlTypeDto>>(items.ToList());

                return new PagedResultDto<SetlTypeDto>(totalCount, itemsDto);
            }
        }
    }
}
